@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul

echo =========================================
echo   GMCM 2025 高质量参数重新运行
echo =========================================
echo 配置: 5000次迭代, 200批量, 300轮, 30分钟, 8线程
echo 运行顺序: FlashAttention_Case1 → Matmul_Case0 → Matmul_Case1 → Conv_Case1
echo 跳过: FlashAttention_Case0, Conv_Case0 (已有结果)
echo ⚠️  包含2个大算例: Matmul_Case1 (31K节点), Conv_Case1 (36K节点)
echo.

REM 检查可执行文件
if not exist "competition_scheduler.exe" (
    echo ❌ 找不到 competition_scheduler.exe
    pause
    exit /b 1
)

REM 创建高质量运行报告
set "summary_file=result-all\high_quality_summary.txt"
echo === GMCM 2025 高质量参数运行报告 === > %summary_file%
echo 运行时间: %date% %time% >> %summary_file%
echo 参数配置: 5000次迭代, 200批量, 300轮, 30分钟限制, 8线程 >> %summary_file%
echo. >> %summary_file%

set start_time=%time%
echo 高质量优化开始时间: %start_time%
echo.

REM ==========================================
REM 第1个: FlashAttention_Case1 (第一个运行)
REM ==========================================
echo [1/4] FlashAttention_Case1 (覆盖之前结果)
echo 数据规模: 6952 节点, 预估运行时间: 15-30分钟
if not exist "result-all\FlashAttention_Case1" mkdir "result-all\FlashAttention_Case1"
echo 开始时间: %time%
.\competition_scheduler.exe "data\CSV-version\FlashAttention_Case1_Nodes.csv" "data\CSV-version\FlashAttention_Case1_Edges.csv" "FlashAttention_Case1" "result-all\FlashAttention_Case1"
if %ERRORLEVEL% equ 0 (
    echo ✅ FlashAttention_Case1 完成 (时间: %time%)
    echo FlashAttention_Case1: 成功完成 >> %summary_file%
) else (
    echo ❌ FlashAttention_Case1 失败
    echo FlashAttention_Case1: 失败 (错误: %ERRORLEVEL%) >> %summary_file%
)
echo.

REM ==========================================
REM 第2个: Matmul_Case0 (重新运行)
REM ==========================================
echo [2/4] Matmul_Case0 (重新运行)
echo 数据规模: 4160 节点, 预估运行时间: 10-20分钟
if not exist "result-all\Matmul_Case0" mkdir "result-all\Matmul_Case0"
echo 开始时间: %time%
.\competition_scheduler.exe "data\CSV-version\Matmul_Case0_Nodes.csv" "data\CSV-version\Matmul_Case0_Edges.csv" "Matmul_Case0" "result-all\Matmul_Case0"
if %ERRORLEVEL% equ 0 (
    echo ✅ Matmul_Case0 完成 (时间: %time%)
    echo Matmul_Case0: 成功完成 >> %summary_file%
) else (
    echo ❌ Matmul_Case0 失败
    echo Matmul_Case0: 失败 (错误: %ERRORLEVEL%) >> %summary_file%
)
echo.

REM ==========================================
REM 第3个: Matmul_Case1 (大算例!)
REM ==========================================
echo [3/4] Matmul_Case1 (大算例)
echo 数据规模: 30977 节点, 预估运行时间: 1-2小时
echo ⚠️  这是第一个大算例，请确保有足够时间
echo.
if not exist "result-all\Matmul_Case1" mkdir "result-all\Matmul_Case1"
echo 开始时间: %time%
.\competition_scheduler.exe "data\CSV-version\Matmul_Case1_Nodes.csv" "data\CSV-version\Matmul_Case1_Edges.csv" "Matmul_Case1" "result-all\Matmul_Case1"
if %ERRORLEVEL% equ 0 (
    echo ✅ Matmul_Case1 完成 (时间: %time%)
    echo Matmul_Case1: 成功完成 >> %summary_file%
) else (
    echo ❌ Matmul_Case1 失败
    echo Matmul_Case1: 失败 (错误: %ERRORLEVEL%) >> %summary_file%
)
echo.

REM ==========================================
REM 第4个: Conv_Case1 (最后运行 - 最大算例!)
REM ==========================================
echo [4/4] Conv_Case1 (最后运行 - 最大算例)
echo ⚠️  警告: 数据规模: 36086 节点, 预估运行时间: 1-3小时
echo ⚠️  这是最耗时的算例，请确保有足够时间
echo.
pause
if not exist "result-all\Conv_Case1" mkdir "result-all\Conv_Case1"
echo 开始时间: %time%
.\competition_scheduler.exe "data\CSV-version\Conv_Case1_Nodes.csv" "data\CSV-version\Conv_Case1_Edges.csv" "Conv_Case1" "result-all\Conv_Case1"
if %ERRORLEVEL% equ 0 (
    echo ✅ Conv_Case1 完成 (时间: %time%)
    echo Conv_Case1: 成功完成 >> %summary_file%
) else (
    echo ❌ Conv_Case1 失败
    echo Conv_Case1: 失败 (错误: %ERRORLEVEL%) >> %summary_file%
)
echo.

REM ==========================================
REM 运行完成总结
REM ==========================================
set end_time=%time%
echo =========================================
echo 高质量参数运行完成！
echo =========================================
echo 开始时间: %start_time%
echo 结束时间: %end_time%
echo.

echo 运行结果汇总:
type %summary_file%
echo.

echo 详细结果请查看各算例目录:
echo - FlashAttention_Case1: result-all\FlashAttention_Case1\
echo - Matmul_Case0: result-all\Matmul_Case0\
echo - Matmul_Case1: result-all\Matmul_Case1\
echo - Conv_Case1: result-all\Conv_Case1\
echo.

echo ✅ 高质量优化批量运行完成！
pause
